﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>接口编辑</title>
    <script src="/Apm/js/CMSEdit.js"></script>
    <style>
       
    </style>
</head>
<body>
    <div class="page">
        <div id="title" class="title">
            
        </div>
        <div class="layui-form layui-form-pane edit-form">

            <div class="layui-form-item">
                <label class="layui-form-label">中文名称</label>
                <div class="layui-input-block">
                    <input id="ChinaAPI" type="text" name="ChinaAPI" required lay-verify="required" placeholder="请输入中文名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" pane>
                <label class="layui-form-label">英文名称</label>
                <div class="layui-input-block">
                    <input id="EnglishAPI" type="text" name="EnglishAPI" required lay-verify="required" placeholder="请输入英文名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea id="Remark" name="Remark" placeholder="请输入备注" class="layui-textarea"></textarea>
                </div>
            </div>
            
            
            <button id="submit" lay-submit lay-filter="submit" style="display:none;"></button>
        </div>

        <div class="edit-submit">
            <button id="truebutton" class="layui-btn layui-btn-lg">提交</button>
        </div>
    </div>
</body>
</html>
<script>
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            form = layui.form;

        var type = MyPublic.getUrlParam('type');
        var id = MyPublic.getUrlParam('id');

        switch (type) {
            case 'add':
                $("#title").html('添加接口');
                
                break;
            case 'edit':
                $("#title").html('编辑接口');
                BindDataModel(id)
                break;
        }
        
        $("#truebutton").click(function () {
            $("#submit").click();
        })
        
        //添加或修改
        form.on('submit(submit)', function (data) {
            //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            var json = data.field;
            
            switch (type) {
                case 'add':
                    ajaxpost({
                        url: 'api/Method/APICreate?Token=' + MyPublic.getToken(),
                        data: json,
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code === "10000") {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭   
                            }
                            else {
                                layer.msg(data.msg);
                            }
                        }
                    })

                    break;
                case 'edit':
                    json.Guid = id;
                    ajaxpost({
                        url: 'api/Method/APIUpdate?Token=' + MyPublic.getToken(),
                        data: json,
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code === "10001") {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭   
                            }
                            else {
                                layer.msg(data.msg);
                            }
                        }
                    })
                    break;
            }
            
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        

    });
    
    function BindDataModel(guid) {
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer,
                form = layui.form;

            ajaxget({
                url: 'api/MethodPublic/APIModel?Guid=' + guid,
                success: function (data) {
                    $("#EnglishAPI").val(data.EnglishAPI);
                    $("#ChinaAPI").val(data.ChinaAPI);
                    $("#Remark").val(data.Remark);
                    
                }
            })
        });
    }
    
</script>